package at.ltasat.classifier.dt;

import java.io.IOException;
import java.io.OutputStream;

import at.ltasat.classifier.Classification;
import at.ltasat.classifier.Classifier;
import at.ltasat.classifier.ClazzManager;
import at.ltasat.classifier.ObjectFeaturesFactory;

final class DecisionTreeClassifier<O, D> extends Classifier<O, D> {

	private final Node<D> root;

	public DecisionTreeClassifier(String name, ClazzManager<D> classManager, ObjectFeaturesFactory<O> factory, Node<D> root) {
		super(name, classManager, factory);
		this.root = root;
	}

	public Node<D> getRoot() {
		return root;
	}

	@Override
	public Classification<O, D> classify(O object) {
		return new Classification<O, D>(object, root.evaluate(getObjectFeatures(object)));
	}

	@Override
	public void write(final OutputStream out) throws IOException {
		DecisionTreeClassifierFactory.writeClassifier(out, this);
	}

}
